package com.interactiveyang.meet;

import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
import oauth.signpost.signature.HmacSha1MessageSigner;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class OAuthMain extends Activity {

	private CommonsHttpOAuthProvider	provider;
	private CommonsHttpOAuthConsumer	consumer;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		provider = new CommonsHttpOAuthProvider(C.OAuth.GET_REQUEST_TOKEN_URL, C.OAuth.GET_ACCESS_TOKEN_URL, C.OAuth.TOKEN_AUTHORIZATION_URL);
		consumer = new CommonsHttpOAuthConsumer(C.OAuth.CONSUMER_KEY, C.OAuth.CONSUMER_SECRET);
		consumer.setMessageSigner(new HmacSha1MessageSigner());

		android.util.Log.v("OAUTH MAIN", "STARTING STAGE ONE");
		new OAuthStageOne(this, provider, consumer).execute();
	}

	@Override
	public void onNewIntent(Intent intent) {
		super.onNewIntent(intent);

		final Uri uri = intent.getData();
		if (uri != null && uri.getScheme().equals(C.OAuth.CALLBACK_SCHEME)) {
			android.util.Log.v("OAUTH MAIN", "STARTING STAGE TWO");
			new OAuthStageTwo(this, provider, consumer).execute(uri);
			finish();	
		}
	}

}
